
const ctxPath = document.getElementById("ctxPath").value;
Vue.config.productionTip = false
new Vue({
    el: '#app',
    data() {
        return {
            left: 'left',
            total: 0,
            listData: [],
            currentPage: 1,
            pageSize: 10,
            loading:false,
            multipleSelection:[],
            form: {
                account : '',
            },
        }
    },
    created() {
        this.myInit();
    },
    methods: {
        headStyle() {
            return "text-align:center;font-weight: 700;"
        }
        ,
        rowStyle({row, column, rowIndex, columnIndex}) {
            if (columnIndex === 2) {
            } else {
                return "text-align:center;height:2px"
            }
        },
        getDateByType(type) {
            var date = new Date();
            var myyear = date.getFullYear();
            var mymonth = date.getMonth() + 1;
            var myweekday = date.getDate();
            if (mymonth < 10) {
                mymonth = '0' + mymonth;
            }
            if (myweekday < 10) {
                myweekday = '0' + myweekday;
            }
            if (type === "year") {
                return myyear;
            } else if (type === "month") {
                return myyear + '-' + mymonth;
            }
            return myyear + '-' + mymonth + '-' + myweekday;
        },
        // 编写日期格式化方法
        dateFormat: function(row, column) {
            const date = row[column.property]
            if (date === undefined) {
                return ''
            }
            // 这里的格式根据需求修改
            return moment(date).format('YYYY-MM-DD HH:mm:ss.SSS')
        },
        myInit() {
            this.form.quertType = 'lineName';
            this.queryData();
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        queryData(){
            let me = this;
            me.loading = true;
            let postData = {
                iDisplayStart: me.currentPage,
                iDisplayLength: me.pageSize,
                sSortDir: "",
                sSortCol: "",
                account: me.form.account
            };
            $.ajax({
                type: "post",
                url:ctxPath+"/user/list",
                data:postData,
                dataType: "json",
                complete: function (data) {
                    data = data.responseJSON;
                    me.listData = data.data.aData;
                    me.total = data.data.iTotalRecords;
                    me.currentPage = 1;
                    me.pageSize = 10;
                    me.loading = false;
                },
                error: function (data) {
                    me.$message({
                        message: '查询失败',
                        type: 'error',
                        duration: 1000,
                        showClose: true
                    });
                    me.loading = false;
                }
            });
        },
        QueryDataRef(){
            let me = this;
            me.loading = true;
            let postData = {
                iDisplayStart: me.iDisplayStart,
                iDisplayLength: me.iDisplayLength,
                sSortDir: "",
                sSortCol: "",
                account: me.form.account
            };
            $.ajax({
                type: "post",
                url:ctxPath+"/user/list",
                data:postData,
                dataType: "json",
                complete: function (data) {
                    data = data.responseJSON;
                    me.listData = data.data.aData;
                    me.loading = false;
                },
                error: function (data) {
                    me.$message({
                        message: '查询失败',
                        type: 'error',
                        duration: 1000,
                        showClose: true
                    });
                    me.loading = false;
                }
            });
        },
        handleSizeChange(val) {
            this.pageSize = val;
            this.currentPage = 1;
            let me = this;
            me.loading = true;
            let postData = {
                iDisplayStart: val,
                iDisplayLength: me.pageSize,
                sSortDir: "",
                sSortCol: "",
                account: me.form.account
            };
            $.ajax({
                type: "post",
                url:ctxPath+"/user/list",
                dataType: "json",
                data:postData,
                complete: function (data) {
                    data = data.responseJSON;
                    me.listData = data.data.aData;
                    me.loading = false;
                },
                error: function (data) {
                    me.$message({
                        message: '查询失败',
                        type: 'error',
                        duration: 1000,
                        showClose: true
                    });
                    me.loading = false;
                }
            });
        },
        handleCurrentChange(val) {
            this.currentPage = val;
            val = this.pageSize * val - 1;
            let me = this;
            me.loading = true;
            let postData = {
                iDisplayStart: val,
                iDisplayLength: me.pageSize,
                sSortDir: "",
                sSortCol: "",
                account: me.form.account
            };
            $.ajax({
                type: "post",
                url:ctxPath+"/user/list",
                dataType: "json",
                data:postData,
                complete: function (data) {
                    data = data.responseJSON;
                    me.listData = data.data.aData;
                    me.loading = false;
                },
                error: function (data) {
                    me.$message({
                        message: '查询失败',
                        type: 'error',
                        duration: 1000,
                        showClose: true
                    });
                    me.loading = false;
                }
            });
        },
        typeIndex(index) {
            return (this.currentPage - 1) * this.pageSize + index + 1;
        }
    }
});